<template>
    <div>
    
      
   
   <el-table
      :data="information.data"
      align="center"
      prop="status"
      style="width: 100%">
      <el-table-column
        prop="orderCode"
        label="订单编号"
        align="center"
        width="130">
      </el-table-column>
      <el-table-column
        prop="secondHand.title"
        label="商品信息"
        align="center"
        width="100">
      </el-table-column>
     
      <el-table-column
        prop="prices"
        align="center"
        label="商品价格">
      </el-table-column>
      <el-table-column
        prop="num"
        align="center"
        label="购买数量">
      </el-table-column>
      <el-table-column
        prop="addr.phone"
        label="电话"
        align="center"
        width="115">
      </el-table-column>
      <el-table-column
        prop="addr.address"
        align="center"
        label="地址">
      </el-table-column>
      <el-table-column
        prop="status"
        align="center"
        width="200"
        label="商品状态">
        <template slot-scope="scope">
       
        <el-tag type="green" v-if="scope.row.status==1" >未支付</el-tag>
        <el-tag type="danger" v-if="scope.row.status==2" >已取消订单</el-tag>
        <el-tag type="danger" v-if="scope.row.status==4" >已退货</el-tag>
        <el-tag type="success" v-if="scope.row.status==3" >已支付</el-tag>
      </template>
      </el-table-column>
      <el-table-column
      fixed="right"
      label="操作"
      width="200">
      <template slot-scope="scope">
        <el-button @click="pay(scope.row)"  v-if="scope.row.status==1" type="success" size="small">支付</el-button>
        <el-button @click="close(scope.row)"  v-if="scope.row.status==1" type="success" size="small">取消订单</el-button>
        <el-button  @click="salesReturn(scope.row)" v-if="scope.row.status==3" type="warning" size="small">退货</el-button>
      </template>
    </el-table-column>
    </el-table>

    <!-- 分页组件，页数小于等于1时不显示 -->
      <el-col>
        <el-pagination
          background
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
          :page-sizes="[5, 10, 15, 20, 25]"
          :page-size="information.size"
          :total="information.total"
          :hide-on-single-page="hidePagination"
          layout="prev, pager, next, sizes, total">
        </el-pagination>
      </el-col>
      
      
          
         <form action="http://localhost:8080/order/paySecond" method="post" id="submit">
             
             <input :value="id" hidden name="id" />
         </form>
         
       
      
     
    </div>
</template>
<script>
    export default {
      data(){
        return {
          information:[],
          idePagination:true,
          
          id:'',
         
          dialogVisible:false,
          hidePagination:false //只有一页是否需要隐藏
        }
      },
      computed:{
        
      },
      methods: {
        editNews:function(){
         this.$router.push("/newSecondHand")
      },
      handleCurrentChange:function(page){
          let size =this.information.size;
          console.log(size,page);
          this.$axios.get("http://localhost:8080/second/getOrderByUid/"+page+"/"+size).then(res=>{
          
          if(res.data.status= "SUCCESS"){
            console.log(res.data.data);
            this.information=res.data.data
          }else{
            alert("最新商品获取失败")
          }
        })
       } ,
       handleSizeChange:function(size){
          let page =this.information.currentPage;
          console.log(size,page);
          this.$axios.get("http://localhost:8080/second/getOrderByUid/"+page+"/"+size).then(res=>{
          
          
       })
      },
      isSta:function(status){
          if(status==0){
            return 未上架
          }
      },
      /* 支付 */
      pay:function(val){
          this.id=val.id
          
          location.href="http://localhost:8080/order/paySecond?id="+val.id
         
          /* var submit = document.getElementById("submit");
          submit.submit(); */
          
      },
      /* 取消订单 */
      close:function(val){
        this.$axios.get("http://localhost:8080/second/setOrderStatus/"+val.id+"/"+2).then(res=>{
          
          if(res.data.status= "SUCCESS"){
            this.$message.success("修改成功")
            val.status=2
          }else{
            this.$message.success("修改失败")
          }
        })
      },
      /* 退货 */
      salesReturn:function(val){
        
        this.$axios.get("http://localhost:8080/second/setOrderStatus/"+val.id+"/"+4).then(res=>{
          
          if(res.data.status= "SUCCESS"){
            this.$message.success("修改成功")
            val.status=4
          }else{
            this.$message.success("修改失败")
          }
        })
        
      }

      },
      mounted() {

        //获取信息
        this.$axios.get("http://localhost:8080/second/getOrderByUid/1/5").then(res => {
          if(res.data.status == "SUCCESS"){
            this.information = res.data.data
            console.log(res.data);
            
          }else{
            this.$message.error("数据加载失败")
          }
        })
      }
    }
</script>

<style scoped>

</style>
